package com.ruoyi.web.controller.webContent;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.ruoyi.webContent.domain.Mt5Point;
import com.ruoyi.webContent.service.IMt5PointService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * mt5PointController
 *
 * @author ruoyi
 * @date 2020-06-29
 */
@Controller
@RequestMapping("/mt5/point")
public class Mt5PointController extends BaseController {
    private String prefix = "system/point";

    @Autowired
    private IMt5PointService mt5PointService;

    @RequiresPermissions("system:point:view")
    @GetMapping()
    public String point() {
        return prefix + "/point";
    }

    /**
     * 查询mt5Point列表
     */
    @RequiresPermissions("system:point:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Mt5Point mt5Point) {
        startPage();
        List<Mt5Point> list = mt5PointService.selectMt5PointList(mt5Point);
        return getDataTable(list);
    }

    /**
     * 导出mt5Point列表
     */
    @RequiresPermissions("system:point:export")
    @Log(title = "mt5Point", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Mt5Point mt5Point) {
        List<Mt5Point> list = mt5PointService.selectMt5PointList(mt5Point);
        ExcelUtil<Mt5Point> util = new ExcelUtil<Mt5Point>(Mt5Point.class);
        return util.exportExcel(list, "point");
    }

    /**
     * 新增mt5Point
     */
    @GetMapping("/add")
    @ResponseBody
    public String add() {
        Mt5Point mt5Point = new Mt5Point();
        mt5Point.setIsDo(1);
        mt5Point.setDoWhat(1);
        mt5Point.setLineDown((long) 0.117);
        mt5Point.setLineUp((long) 1.117);


        System.out.print(JSON.toJSON(mt5Point));
        return prefix + "/add";
    }

    /**
     * 新增保存mt5Point
     */
//    @RequiresPermissions("system:point:add")
    @Log(title = "mt5Point", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(String body) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        request.getLocalAddr();
        //"{'Symbol':'EURUSD','lineDown':'1.12406','doWhat':'48','lineUp':'1.1254292','zy','2.4','zs','10.0'}\u0000" : [ "" ]
        System.out.println("MT5源信号同步成功："+body);
        String pointstr2 = body.substring(body.indexOf("{"), body.indexOf("}"));
        System.out.println(pointstr2);
        return null;
    }

    /**
     * 修改mt5Point
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        Mt5Point mt5Point = mt5PointService.selectMt5PointById(id);
        mmap.put("mt5Point", mt5Point);
        return prefix + "/edit";
    }

    /**
     * 修改保存mt5Point
     */
    @RequiresPermissions("system:point:edit")
    @Log(title = "mt5Point", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Mt5Point mt5Point) {
        return toAjax(mt5PointService.updateMt5Point(mt5Point));
    }

    /**
     * 删除mt5Point
     */
    @RequiresPermissions("system:point:remove")
    @Log(title = "mt5Point", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(mt5PointService.deleteMt5PointByIds(ids));
    }
}
